﻿using PLCS.Shared.Common.Constant;

namespace PLCS.Domain.Solutions;

/// <summary>
/// 方案表
/// </summary>
public class Solution : BaseEntity
{
    /// <summary>
    /// 方案编号
    /// </summary>
    public string SolutionNo { get; set; }

    /// <summary>
    /// 方案名称
    /// </summary>
    public string SolutionName { get; set; }

    /// <summary>
    /// 包含步骤（相当于一对多，不过这里不用外键，怕出错）
    /// </summary>
    public string? SolutionStepStrings { get; set; }

    [NotMapped]
    public List<SolutionStep>? SolutionSteps { get; set; }

    public Solution()
    {
    }

    public Solution(string solutionNo, string solutionName, string solutionStepStrings = null)
    {
        SolutionNo = solutionNo;
        SolutionName = solutionName;
        SolutionStepStrings = solutionStepStrings;
        CreationTime = DateTime.Now;
    }

    public Solution AddStep(SolutionStep step)
    {
        if (string.IsNullOrEmpty(SolutionStepStrings))
            SolutionStepStrings += $"{step.StepNo}";
        else
            SolutionStepStrings += $"{ConstantChar.SplitChar}{step.StepNo}";
        return this;
    }

    public Solution AddSteps(List<SolutionStep> steps)
    {
        foreach (var item in steps)
        {
            if (string.IsNullOrEmpty(SolutionStepStrings))
                SolutionStepStrings += $"{item.StepNo}";
            else
                SolutionStepStrings += $"{ConstantChar.SplitChar}{item.StepNo}";
        }
        return this;
    }
}